<?php
use yii\helpers\Url;

/**
 * @var $this \yii\web\View
 * @var $result array 结果列表
 * @var $keyword string 搜索关键字
 */

$this->title = '功能搜索';
$this->params['breadcrumbs'][] = $this->title;
?>
<ul id="search_result">
    <?php foreach ($result as $url=>$desc) {?>
        <li><a href="<?php echo Url::to([$url]);?>"><?php echo $desc;?></a></li>
    <?php }?>
</ul>
<script>
    /**
     * 关键字高亮
     * @param keyword
     */
    function highlight(keyword) {
        $('#search_result a').each(function() {
            var txt = $(this).html();
            var reg = new RegExp('(' + keyword + ')');
            txt = txt.replace(reg, '<span class="bg-success">$1</span>');
            $(this).html(txt);
        });
    }
</script>
<?php $this->registerJs('highlight("' . $keyword . '")');
